package com.huiquan.icd.controller;

import com.huiquan.analysis.domain.User;
import com.huiquan.framework.base.ReturnData;
import com.huiquan.framework.utils.RequestParamUtil;
import com.huiquan.icd.service.IcdDiseaseSymptomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@Controller
public class IcdDiseaseSymptomController {

	@Autowired
	private IcdDiseaseSymptomService icdDiseaseSymptomService;

	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/icd/disease_symptom_list.htm")
	public ModelAndView list(HttpServletRequest req, HttpServletResponse resp) throws  Exception {
		String tabid = req.getParameter("tabid");

		// 维护页面参数到session
		Map<String, Object> pageParam;
		if (tabid != null && !tabid.isEmpty()) {
			pageParam = new HashMap<>();
			pageParam.put("tabid", tabid);
			pageParam.put("start", "1");
			pageParam.put("exactSearchFlag", "0");
			pageParam.put("check_flag", "0");
			pageParam.put("type", "o");
			req.getSession().setAttribute("pageParam", pageParam);
		} else {
			pageParam = (Map<String, Object>) req.getSession().getAttribute("pageParam");
		}
		String start = RequestParamUtil.getParamByRequestOrSession(req, pageParam, "start");
		String keyword = RequestParamUtil.getParamByRequestOrSession(req, pageParam, "keyword");
		String keyword2 = RequestParamUtil.getParamByRequestOrSession(req, pageParam, "keyword2");
		String exactSearchFlag2 = RequestParamUtil.getParamByRequestOrSession(req, pageParam, "exactSearchFlag2");
		String flag = RequestParamUtil.getParamByRequestOrSession(req, pageParam, "flag");
		String checkFlag = RequestParamUtil.getParamByRequestOrSession(req, pageParam, "check_flag");
		String countPerPageStr = RequestParamUtil.getParamByRequestOrSession(req, pageParam, "countPerPage");
		String type = RequestParamUtil.getParamByRequestOrSession(req, pageParam, "type");
		User user = (User) req.getSession().getAttribute("user");
		String exactSearchFlag = RequestParamUtil.getParamByRequestOrSession(req, pageParam, "exactSearchFlag");
		String searchOwner = RequestParamUtil.getParamByRequestOrSession(req, pageParam, "searchOwner");
		return icdDiseaseSymptomService.list(Integer.parseInt(start), keyword,keyword2, flag,countPerPageStr,user,checkFlag,type,exactSearchFlag,exactSearchFlag2,resp,req,searchOwner);
	}
	
	@ResponseBody
	@RequestMapping(value = "/icd/disease_symptom_change_flag.do")
	public ReturnData changeFlag(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		String ids =req.getParameter("ids");
		String flag = req.getParameter("flag");
		User user = (User) req.getSession().getAttribute("user");

		return icdDiseaseSymptomService.changeFlag(ids,flag,user);
	}
	@ResponseBody
	@RequestMapping(value = "/icd/disease_symptom_submit_page.do")
	public ReturnData submitPage(HttpServletRequest req, HttpServletResponse resp) throws Exception {
		@SuppressWarnings("unchecked")
		Map<String, Object> pageParam = (Map<String, Object>) req.getSession().getAttribute("pageParam");
		User user = (User) req.getSession().getAttribute("user");
		String ids  = req.getParameter("ids");
		String start = RequestParamUtil.getParamByRequestOrSession(req, pageParam, "start");
		String type = (String)(pageParam.get("type") == null?"":pageParam.get("type"));

		return icdDiseaseSymptomService.submitPage(ids, user,start,type );
	}
}
